
/**
 * AppleIIGo
 * Mouse class
 * (C) 2008 by Marc S. Ressl (mressl@umich.edu)
 * Released under the GPL
 */
 
#include "Motherboard.h"

#ifndef MOUSE_H
#define MOUSE_H

#define INTERRUPT_MOUSEENABLED				(1 << 0)
#define INTERRUPT_MOUSEMOVEINTENABLED		(1 << 1)
#define INTERRUPT_MOUSEBUTTONINTENABLED		(1 << 2)
#define INTERRUPT_VBLINTENABLED				(1 << 3)
#define INTERRUPT_QUARTERSECINTENABLED		(1 << 4)

#define INTERRUPTFLAG_IRQASSERTED			(1 << 0)
#define INTERRUPTFLAG_MOUSEMOVEASSERTED		(1 << 1)
#define INTERRUPTFLAG_MOUSEBUTTONASSERTED	(1 << 2)
#define INTERRUPTFLAG_VBLINTASSERTED		(1 << 3)
#define INTERRUPTFLAG_QUARTERSECINTASSERTED	(1 << 4)
#define INTERRUPTFLAG_AN3					(1 << 5)
#define INTERRUPTFLAG_BUTTONLAST			(1 << 6)
#define INTERRUPTFLAG_BUTTONNOW				(1 << 7)

#define INTERRUPTCLEAR_CLEARVBLINT			(1 << 3)
#define INTERRUPTCLEAR_CLEARQUARTERSECINT	(1 << 4)

#define MOUSEBUTTON_NUM						3

class Mouse : public Device {
public:
	Mouse(class Motherboard * motherboard);
	
	void onResetAsserted(bool isRestart);
	
	void pushButton(UINT32 index);
	void pullButton(UINT32 index);
	bool isButtonDown(UINT32 index);
	
	void moveMouse(SINT32 relativeX, SINT32 relativeY);
	
	// Apple IIc mouse
	void enableXYInterrupts(bool value);
	void setXInterruptOnFallingEdge(bool isFallingEdge);
	void setYInterruptOnFallingEdge(bool isFallingEdge);
	bool clearXInterrupt();
	bool clearYInterrupt();
	bool isXYInterruptsEnabled();
	bool isXInterruptOnFallingEdge();
	bool isYInterruptOnFallingEdge();
	bool isXDirectionHigh();
	bool isYDirectionHigh();
	
	// ADB mouse
	
	// Mega II mouse
	void setInterruptRegister(UINT8 value);
	UINT8 getInterruptRegister();
	UINT8 getInterruptFlagRegister();
	UINT8 getDeltaXRegister();
	UINT8 getDeltaYRegister();
	void clearXYInterruptRegister();
	
private:
	class Interrupt * mouseInterrupt;
	
	UINT32 buttonCount[MOUSEBUTTON_NUM];
	
	UINT8 interruptRegister;
	UINT8 interruptFlagRegister;
	
	SINT32 paddleXPosition;
	SINT32 paddleYPosition;
	
	void initButton(UINT32 index);
	void initInterrupt();
};

#endif
